// 帮我写一个不丢失精度的加法函数
let add = (num1:number, num2:number) => {
    let num1Str = num1+"";
    let num2Str = num2+"";
    let num1Digits = (num1Str.split('.')[1] || '').length;
    let num2Digits = (num2Str.split('.')[1] || '').length;
    let baseNum = Math.pow(10, Math.max(num1Digits, num2Digits));
    return (num1 * baseNum + num2 * baseNum) / baseNum;
}

// 帮我写一个不丢失精度的减法函数
let sub = (num1:number, num2:number) => {
    let num1Str = num1+"";
    let num2Str = num2+"";
    let num1Digits = (num1Str.split('.')[1] || '').length;
    let num2Digits = (num2Str.split('.')[1] || '').length;
    let baseNum = Math.pow(10, Math.max(num1Digits, num2Digits));
    return (num1 * baseNum - num2 * baseNum) / baseNum;
}

// 帮我写一个不丢失精度的乘法函数
let mul = (num1:number, num2:number) => {
    let num1Str = num1+"";
    let num2Str = num2+"";
    let num1Digits = (num1Str.split('.')[1] || '').length;
    let num2Digits = (num2Str.split('.')[1] || '').length;
    let baseNum = Math.pow(10, Math.max(num1Digits, num2Digits));
    return (num1 * baseNum) * (num2 * baseNum) / (baseNum * baseNum);
}

// 帮我写一个不丢失精度的除法函数
let div = (num1:number, num2:number) => {
    let num1Str = num1+"";
    let num2Str = num2+"";
    let num1Digits = (num1Str.split('.')[1] || '').length;
    let num2Digits = (num2Str.split('.')[1] || '').length;
    let baseNum = Math.pow(10, Math.max(num1Digits, num2Digits));
    return (num1 * baseNum) / (num2 * baseNum);
}

// 帮我写一个不限参数的加法函数
let addAll = (...args:number[]) => {
    return args.reduce((prev, cur) => {
        return add(prev, cur);
    })
}

// 帮我写一个不限参数的减法函数
let subAll = (...args:number[]) => {
    return args.reduce((prev, cur) => {
        return sub(prev, cur);
    })
}

// 帮我写一个不限参数的乘法函数
let mulAll = (...args:number[]) => {
    return args.reduce((prev, cur) => {
        return mul(prev, cur);
    })
}

// 帮我写一个不限参数的除法函数
let divAll = (...args:number[]) => {
    return args.reduce((prev, cur) => {
        return div(prev, cur);
    })
}

export default {
    add,
    sub,
    mul,
    div,
    addAll,
    subAll,
    mulAll,
    divAll
}